#ifndef InputManager_H
#define InputManager_H

#include <OISMouse.h>
#include <OISKeyboard.h>
#include <OISJoyStick.h>
#include <OISInputManager.h>

class InputManager : public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
{
	InputManager( void );
	InputManager( const InputManager& ) { }
	InputManager & operator = ( const InputManager& );

	bool keyPressed( const OIS::KeyEvent &e );
	bool keyReleased( const OIS::KeyEvent &e );

	bool mouseMoved( const OIS::MouseEvent &e );
	bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
	bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );

	bool povMoved( const OIS::JoyStickEvent &e, int pov );
	bool axisMoved( const OIS::JoyStickEvent &e, int axis );
	bool sliderMoved( const OIS::JoyStickEvent &e, int sliderID );
	bool buttonPressed( const OIS::JoyStickEvent &e, int button );
	bool buttonReleased( const OIS::JoyStickEvent &e, int button );

	OIS::Mouse*			m_mouse;
	OIS::Keyboard*		m_keyboard;
	OIS::InputManager*	m_inputSystem;

	std::vector<OIS::JoyStick*> m_joysticks;
	std::vector<OIS::JoyStick*>::iterator m_itJoystick;
	std::vector<OIS::JoyStick*>::iterator m_itJoystickEnd;

	std::map<std::string, OIS::KeyListener*> m_keyListeners;
	std::map<std::string, OIS::MouseListener*> m_mouseListeners;
	std::map<std::string, OIS::JoyStickListener*> m_joystickListeners;

	std::map<std::string, OIS::KeyListener*>::iterator m_itKeyListener;
	std::map<std::string, OIS::MouseListener*>::iterator m_itMouseListener;
	std::map<std::string, OIS::JoyStickListener*>::iterator m_itJoystickListener;

	std::map<std::string, OIS::KeyListener*>::iterator m_itKeyListenerEnd;
	std::map<std::string, OIS::MouseListener*>::iterator m_itMouseListenerEnd;
	std::map<std::string, OIS::JoyStickListener*>::iterator m_itJoystickListenerEnd;

	static InputManager*	m_inputManager;

public:
	virtual ~InputManager( void );

	void initialise( );
	void capture( void );

	void addKeyListener( OIS::KeyListener* keyListener, const std::string& instanceName );
	void addMouseListener( OIS::MouseListener* mouseListener, const std::string& instanceName );
	void addJoystickListener( OIS::JoyStickListener* joystickListener, const std::string& instanceName );

	void removeKeyListener( const std::string& instanceName );
	void removeMouseListener( const std::string& instanceName );
	void removeJoystickListener( const std::string& instanceName );

	void removeKeyListener( OIS::KeyListener* keyListener );
	void removeMouseListener( OIS::MouseListener* mouseListener );
	void removeJoystickListener( OIS::JoyStickListener* joystickListener );

	void removeAllListeners( void );
	void removeAllKeyListeners( void );
	void removeAllMouseListeners( void );
	void removeAllJoystickListeners( void );

	void setWindowExtents( int width, int height );

	OIS::Mouse*    getMouse( void );
	OIS::Keyboard* getKeyboard( void );
	OIS::JoyStick* getJoystick( unsigned int index );

	int getNumOfJoysticks( void );

	static InputManager* getSingletonPtr( void );	
};

#endif